/**
 * Author: Shen Yanqiu
 * Date: 2018-02-24
 * Time: 14:21
 *
 */
import modelExtend from 'dva-model-extend';
import {pageModel} from '../common';
import {message} from 'antd';
import { delay, routerTool } from "utils";

export default modelExtend(pageModel, {
  namespace: 'forStatistics',
  state: {
    areaChartDate: [],
  },
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {
        if (location.pathname === routerTool.getPathByName('ForStatistics')) {
          dispatch({ type: 'firstLoad' });
        }
      });
    },
  },
  effects: {
    * firstLoad ({ payload = {} }, { put, call }) {
      yield put({
        type: 'loadAreaChartDate',
        payload: {
          checkTime: [],
        },
      });
      yield put({
        type: 'loadTableList',
        payload: {
          current: 0,
          pageSize: 10,
        },
      });
      yield delay(1000);
    },
    * loadAreaChartDate ({ payload: { checkTime } }, { put, call }) {
      // console.log(checkTime);
      const data = [
        {name: '10-23周日', uv: 30, time: '2012-12-01 02:21'},
        {name: '10-24周一', uv: 20, time: '2012-12-01 02:22'},
        {name: '10-25周二', uv: 55, time: '2012-12-01 02:23'},
        {name: '10-26周三', uv: 20, time: '2012-12-01 02:24'},
        {name: '10-27周四', uv: 10, time: '2012-12-01 02:25'},
        {name: '10-28周五', uv: 15, time: '2012-12-01 02:26'},
        {name: '10-29周六', uv: 20, time: '2012-12-01 02:27'},
        {name: '10-30周日', uv: 30, time: '2012-12-01 02:28'},
        {name: '10-31周一', uv: 20, time: '2012-12-01 02:29'},
        {name: '11-01周二', uv: 55, time: '2012-12-01 02:30'},
        {name: '11-02周三', uv: 20, time: '2012-12-01 02:31'},
        {name: '11-03周四', uv: 10, time: '2012-12-01 02:32'},
        {name: '11-04周五', uv: 15, time: '2012-12-01 02:33'},
        {name: '11-04周六', uv: 200, time: '2012-12-01 02:22'},
        {name: '10-23周日', uv: 30, time: '2012-12-01 02:22'},
        {name: '10-24周一', uv: 20, time: '2012-12-01 02:22'},
        {name: '10-25周二', uv: 55, time: '2012-12-01 02:22'},
        {name: '10-26周三', uv: 20, time: '2012-12-01 02:22'},
        {name: '10-27周四', uv: 100, time: '2012-12-01 02:22'},
        {name: '10-28周五', uv: 15, time: '2012-12-01 02:22'},
        {name: '10-29周六', uv: 20, time: '2012-12-01 02:22'},
        {name: '10-30周日', uv: 30, time: '2012-12-01 02:22'},
        {name: '10-31周一', uv: 20, time: '2012-12-01 02:22'},
        {name: '11-01周二', uv: 55, time: '2012-12-01 02:22'},
        {name: '11-02周三', uv: 20, time: '2012-12-01 02:22'},
      ];
      yield put({
        type: 'updateAreaChartDate',
        payload: {
          areaChartDate: data,
        },
      });
    },
    * loadTableList ({ payload = {} }, { put, call }) {
      const data = {
        total: 22,
        list: [{
          key: '1',
          xuhao: '1',
          bumen: '新闻部',
          money: 120,
        }, {
          key: '2',
          xuhao: '2',
          bumen: '活动部',
          money: 113,
        }, {
          key: '3',
          xuhao: '3',
          bumen: '活动部',
          money: 113,
        }, {
          key: '4',
          xuhao: '4',
          bumen: '活动部',
          money: 113,
        }, {
          key: '5',
          xuhao: '5',
          bumen: '活动部',
          money: 113,
        }, {
          key: '6',
          xuhao: '6',
          bumen: '活动部',
          money: 113,
        }, {
          key: '7',
          xuhao: '7',
          bumen: '活动部',
          money: 113,
        }],
      }
      yield put({
        type: 'loadSuccess',
        payload: {
          list: data.list,
          pagination: {
            current: payload.current,
            pageSize: payload.pageSize,
            total: data.total,
          },
        },
      });
      yield delay(2000);
    },
  },
  reducers: {
    updateAreaChartDate (state, { payload: { areaChartDate } }) {
      return { ...state, ...{ areaChartDate } };
    },
  },
});
